// 页面form 与 接口data 数据结构互相转换
import {separator, imageDomain} from '@/common/js/resource.js';
import tool from '@/common/js/tools.js';
// 从业人员
export default {
	/**
	 * 将接口返回的res.data转换成页面的formData
	 * @param {Object} data 接口返回的data
	 * @return {Object} 页面formData
	 */
	newForm(data){
		return {
			id: data.ID,
			companyId: data.QiYeID,
			name: data.XingMing, // 姓名
			physical_code: data.JianKangZhengHao, // 健康证编号
			sexId: data.XingBieID, // 性别
			sex: data.xingbiemingcheng, // 性别
			dutyId: data.ZhiWuID, // 职务
			duty: data.ZhiWuMingCheng, // 职务
			begDate: data.JianKangZhengKaiShiDate, // 证件有效期(起)
			expDate: data.JianKangZhengJieShuDate, // 证件有效期(止)
			sort: '0', // 显示排序
			images1: tool.addImageDomain(data.JianKangZhengZhaoPianUrl), // 健康证照片
			tijian_date: data.TiJianDate, // 体检时间
			images2: tool.addImageDomain(data.TiJianBaoGaoUrl), // 健康体检报告
			jobStatus: data.ZaiZhiZhuangTaiID, // 在职状态 0在职 1离职
		}
	},
	/**
	 * 将接口返回的res.data转换成页面的dataList
	 * @param {Array} list 接口返回的list
	 * @return {Object} 页面dataList
	 */
	newFormList(list){
		/*
		"ID": 2,
		"QiYeID": 1,
		"XingMing": "三丰",
		"XingBieID": 44,
		"xingbiemingcheng": "男",
		"ShenFenZhengHao": "111111222222333333",
		"JianKangZhengHao": "JK1234567890",
		"JianKangZhengKaiShiDate": "2024-01-01",
		"JianKangZhengJieShuDate": "2025-01-01",
		"ZaiZhiZhuangTai": 1,
		"ZhiWuID": 2,
		"ZhiWuMingCheng": "安全员",
		"TiJianDate": "2023-12-25",
		"ZhuangTai": 1,
		"JianKangZhengZhaoPianUrl": "1url",
		"TiJianBaoGaoUrl": null,
		"RecordCount": 1
		*/
		let arr = list.map(data => {
			return {
				id: data.ID,
				companyId: data.QiYeID,
				name: data.XingMing, // 姓名
				physical_code: data.JianKangZhengHao, // 健康证编号
				sexId: data.XingBieID, // 性别
				sex: data.xingbiemingcheng, // 性别
				dutyId: data.ZhiWuID, // 职务
				duty: data.ZhiWuMingCheng, // 职务
				begDate: data.JianKangZhengKaiShiDate, // 证件有效期(起)
				expDate: data.JianKangZhengJieShuDate, // 证件有效期(止)
				sort: '0', // 显示排序
				images1: tool.addImageDomain(data.JianKangZhengZhaoPianUrl), // 健康证照片
				tijian_date: data.TiJianDate, // 体检时间
				images2: tool.addImageDomain(data.TiJianBaoGaoUrl), // 健康体检报告
				jobStatus: data.ZaiZhiZhuangTaiID, // 在职状态 0在职 1离职
			}
		})
		return arr;
	},
	/**
	 * 将页面页面的formData转换成接口需要的data
	 * @param {Object} form 页面formData
	 * @return {Object} 传给接口的data
	 */
	newApiData(data){
		return {
			RenYuanID: data.id || '',
			QiYeID: data.companyId,
			XingMing: data.name, // 姓名
			JianKangZhengHao: data.physical_code, // 健康证编号
			XingBieID: data.sexId, // 性别
			ZhiWuID: data.dutyId, // 职务
			JianKangZhengKaiShiDate: data.begDate, // 证件有效期(起)
			JianKangZhengJieShuDate: data.expDate, // 证件有效期(止)
			JianKangZhengZhaoPianUrl: data.images1.replaceAll(imageDomain, ''), // 健康证照片
			TiJianDate: data.tijian_date, // 体检时间
			TiJianBaoGaoUrl: data.images2.replaceAll(imageDomain, ''), // 健康体检报告
			ZaiZhiZhuangTaiID: data.jobStatus, // 在职状态
		}
	},
	// 比较新form和原form是否相同（无变化）
	compare(form1, form2){
		return form1.id            == form2.id           
			&& form1.companyId     == form2.companyId    
			&& form1.name          == form2.name         
			&& form1.physical_code == form2.physical_code
			&& form1.sexId         == form2.sexId        
			&& form1.sex           == form2.sex          
			&& form1.dutyId        == form2.dutyId       
			&& form1.duty          == form2.duty         
			&& form1.begDate       == form2.begDate      
			&& form1.expDate       == form2.expDate      
			&& form1.sort          == form2.sort         
			&& form1.images1       == form2.images1      
			&& form1.tijian_date   == form2.tijian_date  
			&& form1.images2       == form2.images2 
			&& form1.jobStatus     == form2.jobStatus
	},
}